<?php

namespace App\Jobs\Train;

use App\Models\Train\TrainQuery\TrainQueryLog;
use App\Trip\Train\Log\TicketQueryLog;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ProcessTicketQueryLog implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private TicketQueryLog $log;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(TicketQueryLog $log)
    {
        $this->log = $log;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $data = $this->log->toArray();
        if (!$this->log->isValid()) {
            return;
        }
        $log = new TrainQueryLog();
        $log->createOrUpdate($data);
    }
}
